# coding=utf-8
import MySQLdb

class Mysql(object):
	def __init__(self):
		self.__conn_dict = dict(host="localhost",user="root",passwd="321abcD",db="tb",charset="utf8")
		#如果函数多，且调用数据库多，使用上面语句

	def Get_sql(self,jpg,i,title1,mp):
		try:
			db = MySQLdb.connect(**self.__conn_dict)#db = MySQLdb.connect("localhost","root","321abcD","tb",charset="utf8")
			cursor = db.cursor()
			sql="INSERT INTO `tb`.`haha` (`img`,`yuanlink`,`title`,`mp4`) VALUES ('%s','%s','%s','%s')" % (jpg,i,title1,mp)
			cursor.execute(sql)
			#data =cursor.fetchone()
			db.commit()
			print '\033[35;1m写入数据完成....\033[0m'+'\n'#紫色
		except Exception,e:
			print e
			print '\031[35;1m写入数据失败....\033[0m'+'\n'
		finally:
			db.close()
			cursor.close()
		#return data


# sqler =Mysql()
# data = sqler.Get_sql('111','aaa','bbb','ccc')
#print data